/**
 * 生成树状图
 * @param list 数组
 * @param parentId 分类id
 * @returns Array
 */
export const menuTree = (
  list: any[],
  parentId: number | null,
): any[] | string => {
  if (list.length < 0) return '请传入数组';
  const returnList: any[] = [];
  list.forEach((item) => {
    if (
      item.parent_id === parentId &&
      (item.isDeleted === 0 || !item.isDeleted)
    ) {
      item.children = menuTree(list, item.id);
      returnList.push(item);
    }
  });
  return returnList;
};

/**
 * 模块名: 判断两个数组内的数字是否相同
 */
export const areArraysEqual = (arr1: number[], arr2: number[]): boolean => {
  if (arr1.length !== arr2.length) {
    return true; // 数组长度不同，直接返回false
  }

  // 对数组进行排序，确保顺序一致
  const sortedArr1 = arr1.sort();
  const sortedArr2 = arr2.sort();

  // 比较每个位置上的数字是否相同
  for (let i = 0; i < sortedArr1.length; i++) {
    if (sortedArr1[i] !== sortedArr2[i]) {
      return true; // 数字不相同，返回false
    }
  }

  return false; // 所有数字都相同，返回true
};

export const getCurrentDate = (): string => {
  const currentDate = new Date();
  const currentYear = currentDate.getFullYear();
  const currentMonth = String(currentDate.getMonth() + 1).padStart(2, '0');
  const currentDay = String(currentDate.getDate()).padStart(2, '0');
  return `${currentYear}-${currentMonth}-${currentDay}`;
};
